package com.bood.shimmer.common.enums;

/**
 * <p>
 * 通用结果集响应码
 * </p>
 *
 * @author：bood
 * @date：2020/9/23
 */
public enum ResultEnum {

    // 遵循 HTTP 协议状态码
    DEAL_SUCCESS(200, "处理成功！！！"),
    BODY_NOT_MATCH(400, "请求失败！！！"),
    SIGNATURE_NOT_MATCH(401, "未认证（签名错误）！！！"),
    NOT_FOUND(404, "接口不存在！！！"),
    INTERNAL_SERVER_ERROR(500, "服务器内部错误！！！");

    private Integer code;

    private String message;


    ResultEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }


    public Integer code() {
        return this.code;
    }

    public String message() {
        return this.message;
    }

    public static String getMessage(String name) {
        for (ResultEnum item : ResultEnum.values()) {
            if (item.name().equals(name)) {
                return item.message;
            }
        }
        return name;
    }

    public static Integer getCode(String name) {
        for (ResultEnum item : ResultEnum.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.name();
    }

}
